

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="沧海横流，尽显英雄本色；激浊扬清，正是猛士当时">
  <meta name="author" content="closer">
  <meta name="keywords" content="">
  
  <title>Linux命令速查备忘手册 - closer的自留地</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.6.0/styles/androidstudio.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"blog.zsaa.top","root":"/","version":"1.8.10","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"always","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"baidu":"608f2baddd361128381ad2bf9377bf89","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"YzLqNtMw1YEwwACli1FUsIUM-gzGzoHsz","app_key":"HLUt5izfTvTcbEbOrA59W92a","server_url":"https://yzlqntmw.lc-cn-n1-shared.com"}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Hello</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/mydefault.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Linux命令速查备忘手册">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-06-20 10:37" pubdate>
        2021年6月20日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.8k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      37
       分钟
    </span>
  

  
  
    
      <!-- LeanCloud 统计文章PV -->
      <span id="leancloud-page-views-container" class="post-meta" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="leancloud-page-views"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Linux命令速查备忘手册</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：2021年6月20日 上午
                
              </p>
            
            <div class="markdown-body">
              <blockquote>
<p><strong>本文转载于UP主CodeSheep的<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV14A411378a">Linux速查备忘手册</a>,记录下来备用，然后特别感谢他的辛苦整理和无私分享！！！</strong></p>
</blockquote>
<h2 id="1、关机-重启-注销"><a href="#1、关机-重启-注销" class="headerlink" title="1、关机/重启/注销"></a>1、关机/重启/注销</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>shutdown -h now</td>
<td>即刻关机</td>
</tr>
<tr>
<td>shutdown -h 10</td>
<td>10分钟后关机</td>
</tr>
<tr>
<td>shutdown -h 11:00</td>
<td>11：00关机</td>
</tr>
<tr>
<td>shutdown -h +10</td>
<td>预定时间关机（10分钟后）</td>
</tr>
<tr>
<td>shutdown -c</td>
<td>取消指定时间关机</td>
</tr>
<tr>
<td>shutdown -r now</td>
<td>重启</td>
</tr>
<tr>
<td>shutdown -r 10</td>
<td>10分钟之后重启</td>
</tr>
<tr>
<td>shutdown -r 11:00</td>
<td>定时重启</td>
</tr>
<tr>
<td>reboot</td>
<td>重启</td>
</tr>
<tr>
<td>init 6</td>
<td>重启</td>
</tr>
<tr>
<td>init 0</td>
<td>⽴刻关机</td>
</tr>
<tr>
<td>telinit 0</td>
<td>关机</td>
</tr>
<tr>
<td>poweroff</td>
<td>⽴刻关机</td>
</tr>
<tr>
<td>halt</td>
<td>关机</td>
</tr>
<tr>
<td>sync</td>
<td>buff数据同步到磁盘</td>
</tr>
<tr>
<td>logout</td>
<td>退出登录Shell</td>
</tr>
</tbody></table>
<h2 id="2、系统信息和性能查看"><a href="#2、系统信息和性能查看" class="headerlink" title="2、系统信息和性能查看"></a>2、系统信息和性能查看</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>uname -a</td>
<td>查看内核/OS/CPU信息</td>
</tr>
<tr>
<td>uname -r</td>
<td>查看内核版本</td>
</tr>
<tr>
<td>uname -m</td>
<td>查看处理器架构</td>
</tr>
<tr>
<td>arch</td>
<td>查看处理器架构</td>
</tr>
<tr>
<td>hostname</td>
<td>查看计算机名</td>
</tr>
<tr>
<td>who</td>
<td>显示当前登录系统的⽤户</td>
</tr>
<tr>
<td>who am i</td>
<td>显示登录时的⽤户名</td>
</tr>
<tr>
<td>whoami</td>
<td>显示当前⽤户名</td>
</tr>
<tr>
<td>cat /proc/version</td>
<td>查看linux版本信息</td>
</tr>
<tr>
<td>cat /proc/cpuinfo</td>
<td>查看CPU信息</td>
</tr>
<tr>
<td>cat /proc/interrupts</td>
<td>查看中断</td>
</tr>
<tr>
<td>cat /proc/loadavg</td>
<td>查看系统负载</td>
</tr>
<tr>
<td>uptime</td>
<td>查看系统运⾏时间、⽤户数、负载</td>
</tr>
<tr>
<td>env</td>
<td>查看系统的环境变量</td>
</tr>
<tr>
<td>lsusb -tv</td>
<td>查看系统USB设备信息</td>
</tr>
<tr>
<td>lspci -tv</td>
<td>查看系统PCI设备信息</td>
</tr>
<tr>
<td>lsmod</td>
<td>查看已加载的系统模块</td>
</tr>
<tr>
<td>grep MemTotal /proc/meminfo</td>
<td>查看内存总量</td>
</tr>
<tr>
<td>grep MemFree /proc/meminfo</td>
<td>查看空闲内存量</td>
</tr>
<tr>
<td>free -m</td>
<td>查看内存⽤量和交换区⽤量</td>
</tr>
<tr>
<td>date</td>
<td>显示系统⽇期时间</td>
</tr>
<tr>
<td>cal 2021</td>
<td>显示2021⽇历表</td>
</tr>
<tr>
<td>top</td>
<td>动态显示cpu/内存/进程等情况</td>
</tr>
<tr>
<td>vmstat 1 20</td>
<td>每1秒采⼀次系统状态，采20次</td>
</tr>
<tr>
<td>iostat</td>
<td>查看io读写/cpu使⽤情况</td>
</tr>
<tr>
<td>查看io读写/cpu使⽤情况</td>
<td>查询cpu使⽤情况（1秒⼀次，共10次）</td>
</tr>
<tr>
<td>sar -d 1 10</td>
<td>查询磁盘性能</td>
</tr>
</tbody></table>
<h2 id="3、磁盘和分区"><a href="#3、磁盘和分区" class="headerlink" title="3、磁盘和分区"></a>3、磁盘和分区</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>fdisk -l</td>
<td>查看所有磁盘分区</td>
</tr>
<tr>
<td>swapon -s</td>
<td>查看所有交换分区</td>
</tr>
<tr>
<td>df -h</td>
<td>查看磁盘使⽤情况及挂载点</td>
</tr>
<tr>
<td>df -hl</td>
<td>同上</td>
</tr>
<tr>
<td>du -sh /dir</td>
<td>查看指定某个⽬录的⼤⼩</td>
</tr>
<tr>
<td>du -sk * | sort -rn</td>
<td>从⾼到低依次显示⽂件和⽬录⼤⼩</td>
</tr>
<tr>
<td>mount /dev/hda2 /mnt/hda2</td>
<td>挂载hda2盘</td>
</tr>
<tr>
<td>mount -t ntfs /dev/sdc1 /mnt/usbhd1</td>
<td>指定⽂件系统类型挂载（如ntfs）</td>
</tr>
<tr>
<td>mount -o loop xxx.iso /mnt/cdrom</td>
<td>挂 载 iso ⽂ 件</td>
</tr>
<tr>
<td>umount -v /dev/sda1</td>
<td>通过设备名卸载</td>
</tr>
<tr>
<td>umount -v /mnt/mymnt</td>
<td>通过挂载点卸载</td>
</tr>
<tr>
<td>fuser -km /mnt/hda1</td>
<td>强制卸载(慎⽤)</td>
</tr>
</tbody></table>
<h2 id="4、⽤户和⽤户组"><a href="#4、⽤户和⽤户组" class="headerlink" title="4、⽤户和⽤户组"></a>4、⽤户和⽤户组</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>useradd username</td>
<td>创建⽤户</td>
</tr>
<tr>
<td>userdel -r username</td>
<td>删除⽤户</td>
</tr>
<tr>
<td>usermod -g group_name user_name</td>
<td>修改⽤户的组</td>
</tr>
<tr>
<td>usermod -aG group_name user_name</td>
<td>将⽤户添加到组</td>
</tr>
<tr>
<td>usermod -s /bin/ksh -d /home/codepig –g dev username</td>
<td>修改⽤户username的登录Shell、主⽬录以及⽤户组</td>
</tr>
<tr>
<td>groups test</td>
<td>查看test⽤户所在的组</td>
</tr>
<tr>
<td>groupadd group_name</td>
<td>创建⽤户组</td>
</tr>
<tr>
<td>groupdel group_name</td>
<td>删除⽤户组</td>
</tr>
<tr>
<td>groupmod -n new_name old_name</td>
<td>重命名⽤户组</td>
</tr>
<tr>
<td>su - user_name</td>
<td>su - user_name</td>
</tr>
<tr>
<td>passwd</td>
<td>修改⼝令</td>
</tr>
<tr>
<td>passwd username</td>
<td>修改某⽤户的⼝令</td>
</tr>
<tr>
<td>w</td>
<td>查看活动⽤户</td>
</tr>
<tr>
<td>id username</td>
<td>查看指定⽤户username信息</td>
</tr>
<tr>
<td>last</td>
<td>查看⽤户登录⽇志</td>
</tr>
<tr>
<td>crontab -l</td>
<td>查看当前⽤户的计划任务</td>
</tr>
<tr>
<td>cut -d: -f1 /etc/passwd</td>
<td>查看系统所有⽤户</td>
</tr>
<tr>
<td>cut -d: -f1 /etc/group</td>
<td>查看系统所有组</td>
</tr>
</tbody></table>
<h2 id="5、⽹络和进程管理"><a href="#5、⽹络和进程管理" class="headerlink" title="5、⽹络和进程管理"></a>5、⽹络和进程管理</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>ifconfig</td>
<td>查看⽹络接⼝属性</td>
</tr>
<tr>
<td>ifconfig eth0</td>
<td>查看某⽹卡的配置</td>
</tr>
<tr>
<td>route -n</td>
<td>查看路由表</td>
</tr>
<tr>
<td>netstat -lntp</td>
<td>查看所有监听端⼝</td>
</tr>
<tr>
<td>netstat -antp</td>
<td>查看已经建⽴的TCP连接</td>
</tr>
<tr>
<td>netstat -lutp</td>
<td>查看TCP/UDP的状态信息</td>
</tr>
<tr>
<td>ifup eth0</td>
<td>启⽤eth0⽹络设备</td>
</tr>
<tr>
<td>ifdown eth0</td>
<td>禁⽤eth0⽹络设备</td>
</tr>
<tr>
<td>iptables -L</td>
<td>查看iptables规则</td>
</tr>
<tr>
<td>ifconfig eth0 192.168.1.1 netmask 255.255.255.0</td>
<td>配置ip地址</td>
</tr>
<tr>
<td>dhclient eth0</td>
<td>以dhcp模式启⽤eth0</td>
</tr>
<tr>
<td>route add -net 0/0 gw Gateway_IP</td>
<td>配置默认⽹关</td>
</tr>
<tr>
<td>route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1</td>
<td>配置静态路由到达⽹络’192.168.0.0/16’</td>
</tr>
<tr>
<td>route del 0/0 gw Gateway_IP</td>
<td>删除静态路由</td>
</tr>
<tr>
<td>hostname</td>
<td>查看主机名</td>
</tr>
<tr>
<td>host <a target="_blank" rel="noopener" href="http://www.baidu.com/">www.baidu.com</a></td>
<td>解析主机名</td>
</tr>
<tr>
<td>nslookup <a target="_blank" rel="noopener" href="http://www.baidu.com/">www.baidu.com</a></td>
<td>查询DNS记录，查看域名解析是否正常</td>
</tr>
<tr>
<td>ps -ef</td>
<td>查看所有进程</td>
</tr>
<tr>
<td>ps -ef | grep username</td>
<td>过滤出你需要的进程</td>
</tr>
<tr>
<td>kill -s name</td>
<td>kill指定名称的进程</td>
</tr>
<tr>
<td>kill -s pid</td>
<td>kill指定pid的进程</td>
</tr>
<tr>
<td>top</td>
<td>实时显示进程状态</td>
</tr>
<tr>
<td>vmstat 1 20</td>
<td>每1秒采⼀次系统状态，采20次</td>
</tr>
<tr>
<td>iostat</td>
<td>iostat</td>
</tr>
<tr>
<td>sar -u 1 10</td>
<td>查询cpu使⽤情况（1秒⼀次，共10次）</td>
</tr>
<tr>
<td>sar -d 1 10</td>
<td>查询磁盘性能</td>
</tr>
</tbody></table>
<h2 id="6、常⻅系统服务命令"><a href="#6、常⻅系统服务命令" class="headerlink" title="6、常⻅系统服务命令"></a>6、常⻅系统服务命令</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>chkconfig –list</td>
<td>列出系统服务</td>
</tr>
<tr>
<td>service &lt;服务名&gt; status</td>
<td>查看某个服务</td>
</tr>
<tr>
<td>service &lt;服务名&gt; start</td>
<td>启动某个服务</td>
</tr>
<tr>
<td>service &lt;服务名&gt; stop</td>
<td>终⽌某个服务</td>
</tr>
<tr>
<td>service &lt;服务名&gt; restart</td>
<td>重启某个服务</td>
</tr>
<tr>
<td>systemctl status &lt;服务名&gt;</td>
<td>查看某个服务</td>
</tr>
<tr>
<td>systemctl start &lt;服务名&gt;</td>
<td>启动某个服务</td>
</tr>
<tr>
<td>systemctl stop &lt;服务名&gt;</td>
<td>终⽌某个服务</td>
</tr>
<tr>
<td>systemctl restart &lt;服务名&gt;</td>
<td>重启某个服务</td>
</tr>
<tr>
<td>systemctl enable &lt;服务名&gt;</td>
<td>关闭⾃启动</td>
</tr>
<tr>
<td>systemctl disable &lt;服务名&gt;</td>
<td>关闭⾃启动</td>
</tr>
</tbody></table>
<h2 id="7、⽂件和⽬录操作"><a href="#7、⽂件和⽬录操作" class="headerlink" title="7、⽂件和⽬录操作"></a>7、⽂件和⽬录操作</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>cd &lt;⽬录名&gt;</td>
<td>进⼊某个⽬录</td>
</tr>
<tr>
<td>cd ..</td>
<td>回上级⽬录</td>
</tr>
<tr>
<td>cd ../..</td>
<td>回上两级⽬录</td>
</tr>
<tr>
<td>cd</td>
<td>进个⼈主⽬录</td>
</tr>
<tr>
<td>cd -</td>
<td>回上⼀步所在⽬录</td>
</tr>
<tr>
<td>pwd</td>
<td>显示当前路径</td>
</tr>
<tr>
<td>ls</td>
<td>查看⽂件⽬录列表</td>
</tr>
<tr>
<td>ls -F</td>
<td>查看⽬录中内容（显示是⽂件还是⽬录）</td>
</tr>
<tr>
<td>ls -l</td>
<td>查看⽂件和⽬录的详情列表</td>
</tr>
<tr>
<td>ls -a</td>
<td>查看隐藏⽂件</td>
</tr>
<tr>
<td>ls -lh</td>
<td>查看⽂件和⽬录的详情列表（增强⽂件⼤⼩易读性）</td>
</tr>
<tr>
<td>ls -lSr</td>
<td>查看⽂件和⽬录列表（以⽂件⼤⼩升序查看）</td>
</tr>
<tr>
<td>tree</td>
<td>查看⽂件和⽬录的树形结构</td>
</tr>
<tr>
<td>mkdir &lt;⽬录名&gt;</td>
<td>创建⽬录</td>
</tr>
<tr>
<td>mkdir dir1 dir2</td>
<td>同时创建两个⽬录</td>
</tr>
<tr>
<td>mkdir -p /tmp/dir1/dir2</td>
<td>创建⽬录树</td>
</tr>
<tr>
<td>rm -f file1</td>
<td>删除’file1’⽂件</td>
</tr>
<tr>
<td>rmdir dir1</td>
<td>删除’dir1’⽬录</td>
</tr>
<tr>
<td>rm -rf dir1</td>
<td>删除’dir1’⽬录和其内容</td>
</tr>
<tr>
<td>rm -rf dir1 dir2</td>
<td>同时删除两个⽬录及其内容</td>
</tr>
<tr>
<td>mv old_dir new_dir</td>
<td>重命名/移动⽬录</td>
</tr>
<tr>
<td>cp file1 file2</td>
<td>复制⽂件</td>
</tr>
<tr>
<td>cp dir/* .</td>
<td>复制某⽬录下的所有⽂件⾄当前⽬录</td>
</tr>
<tr>
<td>cp -a dir1 dir2</td>
<td>复制⽬录</td>
</tr>
<tr>
<td>cp -a /tmp/dir1 .</td>
<td>复制⼀个⽬录⾄当前⽬录</td>
</tr>
<tr>
<td>ln -s file1 link1</td>
<td>创建指向⽂件/⽬录的软链接</td>
</tr>
<tr>
<td>ln file1 lnk1</td>
<td>创建指向⽂件/⽬录的物理链接</td>
</tr>
<tr>
<td>find / -name file1</td>
<td>从跟⽬录开始搜索⽂件/⽬录</td>
</tr>
<tr>
<td>find / -user user1</td>
<td>搜索⽤户user1的⽂件/⽬录</td>
</tr>
<tr>
<td>find /dir -name *.bin</td>
<td>在⽬录/dir中搜带有.bin后缀的⽂件</td>
</tr>
<tr>
<td>locate &lt;关键词&gt;</td>
<td>快速定位⽂件</td>
</tr>
<tr>
<td>locate *.mp4</td>
<td>寻找.mp4结尾的⽂件</td>
</tr>
<tr>
<td>whereis &lt;关键词&gt;</td>
<td>显示某⼆进制⽂件/可执⾏⽂件的路径</td>
</tr>
<tr>
<td>which &lt;关键词&gt;</td>
<td>查找系统⽬录下某的⼆进制⽂件</td>
</tr>
<tr>
<td>chmod ugo+rwx dir1</td>
<td>设置⽬录所有者(u)、群组(g)及其他⼈(o)的读（r）写(w)执⾏(x)权限</td>
</tr>
<tr>
<td>chmod go-rwx dir1</td>
<td>移除群组(g)与其他⼈(o)对⽬录的读写执⾏权限</td>
</tr>
<tr>
<td>chown user1 file1</td>
<td>改变⽂件的所有者属性</td>
</tr>
<tr>
<td>chown -R user1 dir1</td>
<td>改变⽬录的所有者属性</td>
</tr>
<tr>
<td>chgrp group1 file1</td>
<td>改变⽂件群组</td>
</tr>
<tr>
<td>chown user1:group1 file1</td>
<td>改变⽂件的所有⼈和群组</td>
</tr>
</tbody></table>
<h2 id="8、⽂件查看和处理"><a href="#8、⽂件查看和处理" class="headerlink" title="8、⽂件查看和处理"></a>8、⽂件查看和处理</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>cat file1</td>
<td>查看⽂件内容</td>
</tr>
<tr>
<td>cat -n file1</td>
<td>查看内容并标示⾏数</td>
</tr>
<tr>
<td>tac file1</td>
<td>从最后⼀⾏开始反看⽂件内容</td>
</tr>
<tr>
<td>more file1</td>
<td>more file1</td>
</tr>
<tr>
<td>less file1</td>
<td>类似more命令，但允许反向操作</td>
</tr>
<tr>
<td>head -2 file1</td>
<td>查看⽂件前两⾏</td>
</tr>
<tr>
<td>tail -2 file1</td>
<td>查看⽂件后两⾏</td>
</tr>
<tr>
<td>tail -f /log/msg</td>
<td>实时查看添加到⽂件中的内容</td>
</tr>
<tr>
<td>grep username hello.txt</td>
<td>在⽂件hello.txt中查找关键词username</td>
</tr>
<tr>
<td>grep ^sheep hello.txt</td>
<td>在⽂件hello.txt中查找以sheep开头的内容</td>
</tr>
<tr>
<td>grep [0-9] hello.txt</td>
<td>选择hello.txt⽂件中所有包含数字的⾏</td>
</tr>
<tr>
<td>sed ‘s/s1/s2/g’ hello.txt</td>
<td>将hello.txt⽂件中的s1替换成s2</td>
</tr>
<tr>
<td>sed ‘/^$/d’ hello.txt</td>
<td>从hello.txt⽂件中删除所有空⽩⾏</td>
</tr>
<tr>
<td>sed ‘/ *#/d; /^$/d’ hello.txt</td>
<td>从hello.txt⽂件中删除所有注释和空⽩⾏</td>
</tr>
<tr>
<td>sed -e ‘1d’ hello.txt</td>
<td>从⽂件hello.txt 中排除第⼀⾏</td>
</tr>
<tr>
<td>sed -n ‘/s1/p’ hello.txt</td>
<td>查看只包含关键词”s1”的⾏</td>
</tr>
<tr>
<td>sed -e ‘s/ *$//‘ hello.txt</td>
<td>删除每⼀⾏最后的空⽩字符</td>
</tr>
<tr>
<td>sed -e ‘s/s1//g’ hello.txt</td>
<td>从⽂档中只删除词汇s1并保留剩余全部</td>
</tr>
<tr>
<td>sed -n ‘1,5p;5q’ hello.txt</td>
<td>查看从第⼀⾏到第5⾏内容</td>
</tr>
<tr>
<td>sed -n ‘5p;5q’ hello.txt</td>
<td>查看第5⾏</td>
</tr>
<tr>
<td>paste file1 file2</td>
<td>合并两个⽂件或两栏的内容</td>
</tr>
<tr>
<td>paste -d ‘+’ file1 file2</td>
<td>合并两个⽂件或两栏的内容，中间⽤”+”区分</td>
</tr>
<tr>
<td>sort file1 file2</td>
<td>排序两个⽂件的内容</td>
</tr>
<tr>
<td>comm -1 file1 file2</td>
<td>⽐较两个⽂件的内容(去除’file1’所含内容)</td>
</tr>
<tr>
<td>comm -2 file1 file2</td>
<td>⽐较两个⽂件的内容(去除’file2’所含内容</td>
</tr>
<tr>
<td>comm -3 file1 file2</td>
<td>⽐较两个⽂件的内容(去除两⽂件共有部分)</td>
</tr>
</tbody></table>
<h2 id="9、打包和解压"><a href="#9、打包和解压" class="headerlink" title="9、打包和解压"></a>9、打包和解压</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>zip xxx.zip file</td>
<td>压缩⾄zip包</td>
</tr>
<tr>
<td>zip -r xxx.zip file1 file2 dir1</td>
<td>将多个⽂件+⽬录压成zip包</td>
</tr>
<tr>
<td>unzip xxx.zip</td>
<td>解压zip包</td>
</tr>
<tr>
<td>tar -cvf xxx.tar file</td>
<td>创建⾮压缩tar包</td>
</tr>
<tr>
<td>tar -cvf xxx.tar file1 file2 dir1</td>
<td>将多个⽂件+⽬录打tar包</td>
</tr>
<tr>
<td>tar -tf xxx.tar</td>
<td>查看tar包的内容</td>
</tr>
<tr>
<td>tar -xvf xxx.tar</td>
<td>解压tar包</td>
</tr>
<tr>
<td>tar -xvf xxx.tar -C /dir</td>
<td>将tar包解压⾄指定⽬录</td>
</tr>
<tr>
<td>tar -cvfj xxx.tar.bz2 dir</td>
<td>创建bz2压缩包</td>
</tr>
<tr>
<td>tar -jxvf xxx.tar.bz2</td>
<td>解压bz2压缩包</td>
</tr>
<tr>
<td>tar -cvfz xxx.tar.gz dir</td>
<td>创建gzip压缩包</td>
</tr>
<tr>
<td>tar -zxvf xxx.tar.gz</td>
<td>解压gzip压缩包</td>
</tr>
<tr>
<td>bunzip2 xxx.bz2</td>
<td>解压bz2压缩包</td>
</tr>
<tr>
<td>bzip2 filename</td>
<td>压缩⽂件</td>
</tr>
<tr>
<td>gunzip xxx.gz</td>
<td>解压gzip压缩包</td>
</tr>
<tr>
<td>gzip filename</td>
<td>压缩⽂件</td>
</tr>
<tr>
<td>gzip -9 filename</td>
<td>最⼤程度压缩</td>
</tr>
</tbody></table>
<h2 id="10、RPM包管理命令"><a href="#10、RPM包管理命令" class="headerlink" title="10、RPM包管理命令"></a>10、RPM包管理命令</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>rpm -qa</td>
<td>查看已安装的rpm包</td>
</tr>
<tr>
<td>rpm -q pkg_name</td>
<td>查询某个rpm包</td>
</tr>
<tr>
<td>rpm -q –whatprovides xxx</td>
<td>显示xxx功能是由哪个包提供的</td>
</tr>
<tr>
<td>rpm -q –whatrequires xxx</td>
<td>显示xxx功能被哪个程序包依赖的</td>
</tr>
<tr>
<td>rpm -q –changelog xxx</td>
<td>显示xxx包的更改记录</td>
</tr>
<tr>
<td>rpm -qi pkg_name</td>
<td>查看⼀个包的详细信息</td>
</tr>
<tr>
<td>rpm -qd pkg_name</td>
<td>查询⼀个包所提供的⽂档</td>
</tr>
<tr>
<td>rpm -qc pkg_name</td>
<td>查看已安装rpm包提供的配置⽂件</td>
</tr>
<tr>
<td>rpm -ql pkg_name</td>
<td>查看⼀个包安装了哪些⽂件</td>
</tr>
<tr>
<td>rpm -qf filename</td>
<td>查看某个⽂件属于哪个包</td>
</tr>
<tr>
<td>rpm -qR pkg_name</td>
<td>查询包的依赖关系</td>
</tr>
<tr>
<td>rpm -ivh xxx.rpm</td>
<td>安装rpm包</td>
</tr>
<tr>
<td>rpm -ivh –test xxx.rpm</td>
<td>测试安装rpm包</td>
</tr>
<tr>
<td>rpm -ivh –nodeps xxx.rpm</td>
<td>安装rpm包时忽略依赖关系</td>
</tr>
<tr>
<td>rpm -e xxx</td>
<td>卸载程序包</td>
</tr>
<tr>
<td>rpm -Fvh pkg_name</td>
<td>升级确定已安装的rpm包</td>
</tr>
<tr>
<td>rpm -Uvh pkg_name</td>
<td>升级rpm包(若未安装则会安装)</td>
</tr>
<tr>
<td>rpm -V pkg_name</td>
<td>RPM包详细信息校验</td>
</tr>
</tbody></table>
<h2 id="11、YUM包管理命令"><a href="#11、YUM包管理命令" class="headerlink" title="11、YUM包管理命令"></a>11、YUM包管理命令</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>yum repolist enabled</td>
<td>显示可⽤的源仓库</td>
</tr>
<tr>
<td>yum search pkg_name</td>
<td>搜索软件包</td>
</tr>
<tr>
<td>yum install pkg_name</td>
<td>下载并安装软件包</td>
</tr>
<tr>
<td>yum install –downloadonly pkg_name</td>
<td>只 下 载 不 安 装</td>
</tr>
<tr>
<td>yum list</td>
<td>显示所有程序包</td>
</tr>
<tr>
<td>yum list installed</td>
<td>查看当前系统已安装包</td>
</tr>
<tr>
<td>yum list updates</td>
<td>查看可以更新的包列表</td>
</tr>
<tr>
<td>yum check-update</td>
<td>查看可升级的软件包</td>
</tr>
<tr>
<td>yum update</td>
<td>更新所有软件包</td>
</tr>
<tr>
<td>yum update pkg_name</td>
<td>升级指定软件包</td>
</tr>
<tr>
<td>yum deplist pkg_name</td>
<td>列出软件包依赖关系</td>
</tr>
<tr>
<td>yum remove pkg_name</td>
<td>删除软件包</td>
</tr>
<tr>
<td>yum clean all</td>
<td>清除缓存</td>
</tr>
<tr>
<td>yum clean packages</td>
<td>清除缓存的软件包</td>
</tr>
<tr>
<td>yum clean headers</td>
<td>清除缓存的header</td>
</tr>
</tbody></table>
<h2 id="12、DPKG包管理命令"><a href="#12、DPKG包管理命令" class="headerlink" title="12、DPKG包管理命令"></a>12、DPKG包管理命令</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>dpkg -c xxx.deb</td>
<td>列出deb包的内容</td>
</tr>
<tr>
<td>dpkg -i xxx.deb</td>
<td>安装/更新deb包</td>
</tr>
<tr>
<td>dpkg -r pkg_name</td>
<td>移除deb包</td>
</tr>
<tr>
<td>dpkg -P pkg_name</td>
<td>移除deb包(不保留配置)</td>
</tr>
<tr>
<td>dpkg -l</td>
<td>查看系统中已安装deb包</td>
</tr>
<tr>
<td>dpkg -l pkg_name</td>
<td>显示包的⼤致信息</td>
</tr>
<tr>
<td>dpkg -L pkg_name</td>
<td>查看deb包安装的⽂件</td>
</tr>
<tr>
<td>dpkg -s pkg_name</td>
<td>查看包的详细信息</td>
</tr>
<tr>
<td>dpkg –unpack xxx.deb</td>
<td>解开deb包的内容</td>
</tr>
</tbody></table>
<h2 id="13、APT软件⼯具"><a href="#13、APT软件⼯具" class="headerlink" title="13、APT软件⼯具"></a>13、APT软件⼯具</h2><table>
<thead>
<tr>
<th>常用命令</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>apt-cache search pkg_name</td>
<td>搜索程序包</td>
</tr>
<tr>
<td>apt-cache show pkg_name</td>
<td>获取包的概览信息</td>
</tr>
<tr>
<td>apt-get install pkg_name</td>
<td>安装/升级软件包</td>
</tr>
<tr>
<td>apt-get purge pkg_name</td>
<td>卸载软件（包括配置）</td>
</tr>
<tr>
<td>apt-get remove pkg_name</td>
<td>卸载软件（不包括配置）</td>
</tr>
<tr>
<td>apt-get update</td>
<td>更新包索引信息</td>
</tr>
<tr>
<td>apt-get upgrade</td>
<td>更新已安装软件包</td>
</tr>
<tr>
<td>apt-get clean</td>
<td>清理缓存</td>
</tr>
</tbody></table>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a>
                    
                      <a class="hover-with-bg" href="/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Linux/">Linux</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Linux/">Linux</a>
                    
                      <a class="hover-with-bg" href="/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/10/14/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">操作系统</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/02/03/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/VB/Excel-VBA/">
                        <span class="hidden-mobile">Excel_VBA</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', function () {
        new Valine({
          el: "#valine",
          app_id: "YzLqNtMw1YEwwACli1FUsIUM-gzGzoHsz",
          app_key: "HLUt5izfTvTcbEbOrA59W92a",
          placeholder: "畅所欲言...",
          path: window.location.pathname,
          avatar: "robohash",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: true,
          recordIP: false,
          serverURLs: "",
        });
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->

  <div class="col-lg-7 mx-auto nopadding-x-md">
    <div class="container custom post-custom mx-auto">
      <img src="https://closer_laps.coding.net/p/picture/d/picture/git/raw/master/pay/pay.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-3" style="width:355.4px; height:200px;">
    </div>
  </div>


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- LeanCloud 统计PV -->
        <span id="leancloud-site-pv-container" style="display: none">
            总访问量 
            <span id="leancloud-site-pv"></span>
             次
          </span>
      
      
        <!-- LeanCloud 统计UV -->
        <span id="leancloud-site-uv-container" style="display: none">
            总访客数 
            <span id="leancloud-site-uv"></span>
             人
          </span>
      

    
  </div>


  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        苏ICP备20032307号
      </a>
    </span>
    
      
        <span>
          <a
            href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=32020602001023"
            rel="nofollow noopener"
            class="beian-police"
            target="_blank"
          >
            
              <span style="visibility: hidden; width: 0">|</span>
              <img src="/img/police_beian.png" srcset="/img/loading.gif" lazyload alt="police-icon"/>
            
            <span>苏公网安备 32020602001023号</span>
          </a>
        </span>
      
    
  </div>


  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.2/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js" ></script>




  <script defer src="/js/leancloud.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "/local-search.xml";
      $('#local-search-input').on('click', function() {
        searchFunc(path, 'local-search-input', 'local-search-result');
      });
      $('#modalSearch').on('shown.bs.modal', function() {
        $('#local-search-input').focus();
      });
    })()
  </script>





  

  
    <!-- MathJax -->
    <script>
      MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']]
        },
        options: {
          renderActions: {
            findScript: [10, doc => {
              document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
                const display = !!node.type.match(/; *mode=display/);
                const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
                const text = document.createTextNode('');
                node.parentNode.replaceChild(text, node);
                math.start = { node: text, delim: '', n: 0 };
                math.end = { node: text, delim: '', n: 0 };
                doc.math.push(math);
              });
            }, '', false],
            insertedScript: [200, () => {
              document.querySelectorAll('mjx-container').forEach(node => {
                let target = node.parentNode;
                if (target.nodeName.toLowerCase() === 'li') {
                  target.parentNode.classList.add('has-jax');
                }
              });
            }, '', false]
          }
        }
      };
    </script>

    <script async src="https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js" ></script>

  








  
    <!-- Baidu Analytics -->
    <script defer>
      var _hmt = _hmt || [];
      (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?608f2baddd361128381ad2bf9377bf89";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
  

  

  

  

  

  





<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
